package net.diaowen.dwsurvey.task;

import net.diaowen.dwsurvey.service.SurveyTodoTaskManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class SurveyTodoScheduleTask {

    @Autowired
    private SurveyTodoTaskManager surveyTodoTaskManager;

    //每隔5秒执行一次该方法
    @Scheduled(cron = "*/5 * * * * ?")
    public void sendTodoTaskSimple() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("发起代办定时任务" + Thread.currentThread().getName() + sdf.format(new Date()));
        surveyTodoTaskManager.startTodoTask();
    }

    //每隔5秒执行一次该方法
    @Scheduled(cron = "*/5 * * * * ?")
    public void sendDoTaskSimple() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("完成代办定时任务" + Thread.currentThread().getName() + sdf.format(new Date()));
        surveyTodoTaskManager.endTodoTask();
    }

}